package com.mashibing.vector;

public class Spiral_Matrix {
    //螺旋数组
    public int[][] spiral_Matrix(int n){
        int startX = 0;
        int startY = 0;
        int offset=1;
        int count=0;
        int[][] ret = new int[n][n];
        int i=0,j=0;
        int loop=n/2;
        while(loop>0){
            for(j=startY;j<n-offset;j++){
                System.out.print("X:"+startX+"Y:"+j);
                System.out.println("数值"+count);
                ret[startX][j]=count++;
            }
            for(i=startX;i<n-offset;i++){
                System.out.print("X:"+i+"Y:"+j);
                System.out.println("数值"+count);
                ret[i][j]=count++;

            }
            for(;j>startY;j--){
                System.out.print("X:"+i+"Y:"+j);
                System.out.println("数值"+count);;
                ret[i][j]=count++;

            }
            for(;i>startX;i--){
                System.out.print("X:"+i+"Y:"+j);
                System.out.println("数值"+count);
                ret[i][j]=count++;
            }

            startX++;
            startY++;
            offset++;
            loop--;
        }

        if (n%2==1) {
            ret[n/2][n/2]=count++;
        }

        return ret;
    }
}
